$(document).ready(function() {
	$('.panel-group .panel-default:first-child').addClass('active');
			
	$('.panel-default').on('show.bs.collapse', function () {
		$(this).addClass('active');
	});
	
	$('.panel-default').on('hide.bs.collapse', function () {
		$(this).removeClass('active');
	});
	
	$(".search-select").select2({
	    placeholder: "Select a State",
	    allowClear: true
	});
	
	if(typeof firstMap != 'undefined') {
		runMaps(0);
	}
});	

$('#id_tinh_thanh').on('change', '', function (e) {
	$.post($('#id_tinh_thanh').attr('rel'), { id: $('#id_tinh_thanh').val() }, function( data ) {
		  $( "#id_quan_huyen" ).html( data );
	});
});

$('.tinhlaisuatthang .id_danh_muc').on('change', '', function (e) {
	$.post($(this).attr('rel'), { id: $(this).val() }, function( data ) {
		$("#thoi_han_vay").html( data );
		$("#sidebar #thoi_han_vay").html( data );
	});
});

$('.menu-tinhlaisuatthang form.tinhlaisuatthang').submit(function( event ) {
	  event.preventDefault();
	  $.get('/index/tinh-lai-suat-thang', $(this).serializeArray(), function( data ) {
		  $('.menu-tinhlaisuatthang form.tinhlaisuatthang').replaceWith(data);
	  });
});

function runMaps(i) {
	var map = firstMap[i];
	if (map) {
		$('#mapDiemDichVu').html(map.iframe);
	}
}